package com.xiaoxu.intranetweb.util.excel.strategy;

import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.util.Iterator;

public class CustomCellWriteHeightStrategy extends AbstractRowHeightStyleStrategy {
    /**
     * 默认高度
     */
    private static final Integer DEFAULT_HEIGHT = 200;

    @Override
    protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
        if (relativeRowIndex == 0) {
            row.setHeight((short) (5 * DEFAULT_HEIGHT));
        }else {
            row.setHeight((short) (3 * DEFAULT_HEIGHT));
        }

    }

    @Override
    protected void setContentColumnHeight(Row row, int relativeRowIndex) {
//        Iterator<Cell> cellIterator = row.cellIterator();
//        if (!cellIterator.hasNext()) {
//            return;
//        }
//
//        // 默认为 1行高度
//        Integer maxHeight = 2;
//        while (cellIterator.hasNext()) {
//            Cell cell = cellIterator.next();
//            switch (cell.getCellTypeEnum()) {
//                case STRING:
//                    if (cell.getStringCellValue().indexOf("\n") != -1) {
//                        int length = cell.getStringCellValue().split("\n").length;
//                        maxHeight = Math.max(maxHeight, length);
//                    }
//                    break;
//                default:
//                    break;
//            }
//        }
        if (relativeRowIndex == 24) {
            row.setHeight((short) (4 * DEFAULT_HEIGHT));
        } else if (relativeRowIndex == 25) {
            row.setHeight((short) (5 * DEFAULT_HEIGHT));
        }else {
            row.setHeight((short) (2.4 * DEFAULT_HEIGHT));
        }
    }
}
